﻿using Mengsk.ProxyDelivery.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Mengsk.ProxyDelivery.App.UI.Order
{
    /// <summary>
    /// OrdeDeliveryNumberUpate.xaml 的交互逻辑
    /// </summary>
    public partial class OrdeModifyDeliveryInfoWindow : Window
    {
        public Mengsk.ProxyDelivery.Domain.Order Order { get; set; }

        public OrdeModifyDeliveryInfoWindow()
        {
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                var delivery = ServiceContainer.GetService<DeliveryTemplateService>().GetAll().Datas;
                this.cbbDeliveryCompany.ItemsSource = delivery;
                this.cbbDeliveryCompany.SelectedItem = delivery.FirstOrDefault(obj => Order.DeliveryTemplateId == obj.Id);
                this.tbDeliveryNumber.Text = Order.DeliveryNumber;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                OrderService os = ServiceContainer.GetService<OrderService>();
                var delivery = this.cbbDeliveryCompany.SelectedItem as Mengsk.ProxyDelivery.Domain.DeliveryTemplate;
                string number = this.tbDeliveryNumber.Text.Trim();

                if (delivery == null)
                {
                    MessageBox.Show("选择运费模板");
                    return;
                }
                os.ModifyDeliveryInfo(this.Order.Id, delivery.Id, number, this.chkCutPaperMoney.IsChecked.Value);
                MessageBox.Show("更新成功");
                this.DialogResult = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        }
    }
}
